Python shows name error for a dictionary that exists